import { Entity, Column, PrimaryGeneratedColumn, Index } from 'typeorm';

@Entity('operation_logs')
@Index(['userId', 'createdAt'])
@Index(['operationType', 'createdAt'])
export class OperationLog {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ nullable: true })
  userId?: number;

  @Column({ nullable: true, length: 50 })
  username?: string;

  @Column({ nullable: true, length: 20 })
  phone?: string;

  @Column({ length: 10 })
  method: string;

  @Column({ length: 255 })
  path: string;

  @Column('text', { nullable: true })
  params?: string;

  @Column('text', { nullable: true })
  body?: string;

  @Column({ length: 20 })
  operationType: string; // 操作类型：AUTH/USER/QUERY/CREATE/UPDATE/DELETE/OTHER

  @Column({ nullable: true, length: 50 })
  ip?: string;

  @Column({ nullable: true, length: 255 })
  userAgent?: string;

  @Column()
  status: number;

  @Column()
  duration: number;

  @Column({ 
    type: 'timestamp',
    default: () => 'CURRENT_TIMESTAMP',
    precision: 0  // 移除毫秒精度
  })
  createdAt: Date;
}






